import 'package:flutter/material.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import 'refresh_controller.dart';

class RefreshComponent extends StatelessWidget {
  const RefreshComponent({
    super.key,
    required this.controller,
    required this.child,
    this.onRefresh,
    this.onLoading,
  });

  final RefreshComponentController controller;

  final Widget child;

  final VoidCallback? onRefresh;

  final VoidCallback? onLoading;

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
      controller: controller.refreshController,
      header: controller.classicHeader(),
      footer: controller.classicFooter(),
      enablePullUp: onLoading != null,
      enablePullDown: onRefresh != null,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: child,
    );
  }
}
